package cn.zwx.demo.controller;


import cn.zwx.demo.service.IndexService;
import cn.zwx.mvcframework.annotation.ZwxAutowired;
import cn.zwx.mvcframework.annotation.ZwxController;
import cn.zwx.mvcframework.annotation.ZwxRequestMapping;
import cn.zwx.mvcframework.annotation.ZwxRequestParam;
import cn.zwx.mvcframework.webmvc.servlet.ZwxModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;

/**
 *
 * @author zhangwenxue
 * @date 2022/4/24 10:28
*/
@ZwxController
@ZwxRequestMapping("/cn/zwx/demo")
public class IndexController {

    @ZwxAutowired
    private IndexService indexService;

    @ZwxRequestMapping("/query")
    public String query(@ZwxRequestParam("name") String name,@ZwxRequestParam("from") String from){
        String result = indexService.query(name,from);
        Map<String, String> stringStringMap = new HashMap<>(4);
        stringStringMap.put("result",result);
        stringStringMap.put("code","200");
        return stringStringMap.toString();
    }


    @ZwxRequestMapping("/index")
    public String sayHello(@ZwxRequestParam("name") String name){
        return indexService.sayHello(name);
    }

    @ZwxRequestMapping("/noAnnotation")
    public String noAnnotation(String name){

        return indexService.noAnnotation(name);
    }

    @ZwxRequestMapping("/noParams")
    public String noParams(){
        return indexService.noParams();
    }

    @ZwxRequestMapping("/first")
    public ZwxModelAndView pageFirst(@ZwxRequestParam("name") String name){
        Map<String,Object> model = new HashMap<>(8);
        model.put("name", name);
        model.put("data", "学哥是个大帅比！");
        model.put("token", ThreadLocalRandom.current().nextInt(10000,99999));
        return new ZwxModelAndView("first.html",model);
    }


}
